﻿using System;
using System.Collections.Generic;
using Microsoft.Practices.Unity;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Workbench.Core;
using SharedGenomics.Workbench.Tests.TestObjects;

namespace SharedGenomics.Workbench.Tests.Core
{
    [TestClass]
    public class EventBrokerRegistrationContainerExtensionTests
    {
        private IUnityContainer container;

        [TestInitialize]
        public void Setup()
        {
            this.container = new UnityContainer();
            container.RegisterType<IEventBroker, EventBroker>(new ContainerControlledLifetimeManager());
            container.RegisterType<MultiEventSubscriber>();
            container.AddNewExtension<EventBrokerRegistrationContainerExtension>();
        }

        [TestMethod]
        public void ShouldBeRegisteredForEvents()
        {
            var sub = this.container.Resolve<MultiEventSubscriber>();
            IEventBroker eventBroker = this.container.Resolve<IEventBroker>();
            eventBroker.Publish(new object());
            eventBroker.Publish("abc");

            Assert.IsNotNull(sub.LastObjectMessage);
            Assert.AreEqual("abc", sub.LastStringMessage);
        }

        [TestMethod]
        public void ShouldBeResolved()
        {
            object o = this.container.Resolve<object>();
        }
    }
}
